<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic|LiSu:300,300italic,400,400italic,700,700italic|youyuan:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/blog/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="/blog/lib/pace/pace-theme-bounce.min.css">
  <script src="/blog/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"zchao666.gitee.io","root":"/blog/","scheme":"Gemini","version":"7.7.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="源码（GitHub）：Mybatis级联查询 一对一级联查询一对一级联关系在生活中十分常见，比如一个学生只有一张校园卡，一张校园卡只属于一个学生；再如人与身份证的关系也是一对一级联关系。那么在mybatis中，如何处理这样的一对一级联查询呢？在Mybatis中，通过&lt; resultMap&gt;元素的子元素&lt; association&gt;处理一对一级联关系。">
<meta property="og:type" content="article">
<meta property="og:title" content="Mybatis级联查询">
<meta property="og:url" content="https://zchao666.gitee.io/blog/2020/03/01/Mybatis%E7%BA%A7%E8%81%94%E6%9F%A5%E8%AF%A2/index.html">
<meta property="og:site_name" content="小郭的博客">
<meta property="og:description" content="源码（GitHub）：Mybatis级联查询 一对一级联查询一对一级联关系在生活中十分常见，比如一个学生只有一张校园卡，一张校园卡只属于一个学生；再如人与身份证的关系也是一对一级联关系。那么在mybatis中，如何处理这样的一对一级联查询呢？在Mybatis中，通过&lt; resultMap&gt;元素的子元素&lt; association&gt;处理一对一级联关系。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200229203319903.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMTkzMTMz,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200301002550671.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMTkzMTMz,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200301154020832.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMTkzMTMz,size_16,color_FFFFFF,t_70">
<meta property="article:published_time" content="2020-03-01T07:54:12.000Z">
<meta property="article:modified_time" content="2020-03-05T18:20:42.720Z">
<meta property="article:author" content="小郭">
<meta property="article:tag" content="Java">
<meta property="article:tag" content="Mybatis">
<meta property="article:tag" content="SQL">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/20200229203319903.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMTkzMTMz,size_16,color_FFFFFF,t_70">

<link rel="canonical" href="https://zchao666.gitee.io/blog/2020/03/01/Mybatis%E7%BA%A7%E8%81%94%E6%9F%A5%E8%AF%A2/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true
  };
</script>

  <title>Mybatis级联查询 | 小郭的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

  
  
		<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
		<script>
		/* 社会主体核心价值观效果 */
		var a_idx = 0;
		jQuery(document).ready(function ($) {
		  $("body").click(function (e) {
			var a = new Array("富强", "民主", "文明", "和谐", "自由", "平等", "公正", "法治", "爱国", "敬业", "诚信", "友善");
			var $i = $("<span/>").text(a[a_idx]);
			a_idx = (a_idx + 1) % a.length;
			var x = e.pageX,
			  y = e.pageY;
			$i.css({
			  "z-index": 100000000,
			  "top": y - 20,
			  "left": x,
			  "position": "absolute",
			  "font-family": "LiSu",
			  "font-weight": "bold",
			  "color": "#ff6651"
			});
			$("body").append($i);
			$i.animate({
			  "top": y - 180,
			  "opacity": 0
			}, 1500, function () {
			  $i.remove();
			});
		  });
		});
	</script>
  

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <div>
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">小郭的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/blog/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/blog/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-留言">

    <a href="/blog/comments/" rel="section"><i class="fa fa-fw fa-commenting"></i>留言</a>

  </li>
        <li class="menu-item menu-item-commonweal">

    <a href="/blog/404/" rel="section"><i class="fa fa-fw fa-heartbeat"></i>公益 404</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

  <a href="https://github.com/GZC986707252" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://zchao666.gitee.io/blog/2020/03/01/Mybatis%E7%BA%A7%E8%81%94%E6%9F%A5%E8%AF%A2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/uploads/avatar.jpg">
      <meta itemprop="name" content="小郭">
      <meta itemprop="description" content="一个还在不断学习的编程小白！">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="小郭的博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Mybatis级联查询
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-03-01 15:54:12" itemprop="dateCreated datePublished" datetime="2020-03-01T15:54:12+08:00">2020-03-01</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-03-06 02:20:42" itemprop="dateModified" datetime="2020-03-06T02:20:42+08:00">2020-03-06</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/Mybatis%E5%AD%A6%E4%B9%A0/" itemprop="url" rel="index"><span itemprop="name">Mybatis学习</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/blog/2020/03/01/Mybatis%E7%BA%A7%E8%81%94%E6%9F%A5%E8%AF%A2/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/blog/2020/03/01/Mybatis%E7%BA%A7%E8%81%94%E6%9F%A5%E8%AF%A2/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>源码（GitHub）：<a href="https://github.com/GZC986707252/MybatisSelectDemo.git" target="_blank" rel="noopener">Mybatis级联查询</a></p>
<h3 id="一对一级联查询"><a href="#一对一级联查询" class="headerlink" title="一对一级联查询"></a>一对一级联查询</h3><p>一对一级联关系在生活中十分常见，比如一个学生只有一张校园卡，一张校园卡只属于一个学生；再如人与身份证的关系也是一对一级联关系。那么在mybatis中，如何处理这样的一对一级联查询呢？<br>在Mybatis中，通过&lt; resultMap&gt;元素的子元素&lt; association&gt;处理一对一级联关系。</p>
<a id="more"></a>
<p><strong>&lt; association&gt;的相关属性：</strong></p>
<ul>
<li>property： 指定映射到实体类的对象属性。</li>
<li>column ：指定数据表中对应的字段（即查询返回的列名）。</li>
<li>javaType：指定映射到实体类的对象属性类型。</li>
<li>select ：指定引入嵌套查询的子SQL语句，该属性用于映射关联中的嵌套查询。</li>
</ul>
<p><strong>以人和身份证的一对一关系为例：</strong><br>分别在数据库中创建了User表和idcard表，两个表的关系就是一对一的关系。<br><strong>根据表的信息，创建相应的持久化类：</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">IdCard</span> </span>&#123;</span><br><span class="line">	<span class="comment">//对应数据表的字段</span></span><br><span class="line">    <span class="keyword">private</span> Integer id;</span><br><span class="line">    <span class="keyword">private</span> String code;</span><br><span class="line">	</span><br><span class="line">	<span class="comment">//省略了getter和setter方法</span></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">toString</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">"IdCard&#123;"</span> +</span><br><span class="line">                <span class="string">"id="</span> + id +</span><br><span class="line">                <span class="string">", code='"</span> + code + <span class="string">'\''</span> +</span><br><span class="line">                <span class="string">'&#125;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">User</span> </span>&#123;</span><br><span class="line">	<span class="comment">//对应数据表的字段</span></span><br><span class="line">    <span class="keyword">private</span> Integer id;</span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="keyword">private</span> Integer age;</span><br><span class="line">    <span class="keyword">private</span> IdCard idCard;</span><br><span class="line">    </span><br><span class="line">	<span class="comment">//省略了getter和setter方法</span></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">toString</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">"User&#123;"</span> +</span><br><span class="line">                <span class="string">"id="</span> + id +</span><br><span class="line">                <span class="string">", name='"</span> + name + <span class="string">'\''</span> +</span><br><span class="line">                <span class="string">", age="</span> + age +</span><br><span class="line">                <span class="string">", idCard="</span> + idCard +</span><br><span class="line">                <span class="string">'&#125;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>创建映射文件：</strong><br>IdCardMapper.xml</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version&#x3D;&quot;1.0&quot; encoding&#x3D;&quot;UTF-8&quot;?&gt;</span><br><span class="line">&lt;!DOCTYPE mapper</span><br><span class="line">        PUBLIC &quot;-&#x2F;&#x2F;mybatis.org&#x2F;&#x2F;DTD Mapper 3.0&#x2F;&#x2F;EN&quot;</span><br><span class="line">        &quot;http:&#x2F;&#x2F;mybatis.org&#x2F;dtd&#x2F;mybatis-3-mapper.dtd&quot;&gt;</span><br><span class="line">&lt;mapper namespace&#x3D;&quot;gzc.dao.IdCardDao&quot;&gt;</span><br><span class="line">    &lt;!--根据id查询身份证号码--&gt;</span><br><span class="line">    &lt;select id&#x3D;&quot;selectCodeById&quot; resultType&#x3D;&quot;gzc.pojo.IdCard&quot; parameterType&#x3D;&quot;Integer&quot;&gt;</span><br><span class="line">        select * from idcard where id&#x3D;#&#123;id&#125;</span><br><span class="line">    &lt;&#x2F;select&gt;</span><br><span class="line">&lt;&#x2F;mapper&gt;</span><br></pre></td></tr></table></figure>
<p>UserMapper.xml</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version&#x3D;&quot;1.0&quot; encoding&#x3D;&quot;UTF-8&quot;?&gt;</span><br><span class="line">&lt;!DOCTYPE mapper</span><br><span class="line">        PUBLIC &quot;-&#x2F;&#x2F;mybatis.org&#x2F;&#x2F;DTD Mapper 3.0&#x2F;&#x2F;EN&quot;</span><br><span class="line">        &quot;http:&#x2F;&#x2F;mybatis.org&#x2F;dtd&#x2F;mybatis-3-mapper.dtd&quot;&gt;</span><br><span class="line">&lt;mapper namespace&#x3D;&quot;gzc.dao.UserDao&quot;&gt;</span><br><span class="line">    &lt;!--根据id查个人信息--&gt;</span><br><span class="line">    &lt;!-- 一对一级联查询方法一：嵌套查询，执行两个SQL语句 --&gt;</span><br><span class="line">    &lt;resultMap type&#x3D;&quot;gzc.pojo.User&quot; id&#x3D;&quot;userAndIdCard_1&quot;&gt;</span><br><span class="line">        &lt;id property&#x3D;&quot;id&quot; column&#x3D;&quot;id&quot;&#x2F;&gt;</span><br><span class="line">        &lt;result property&#x3D;&quot;name&quot; column&#x3D;&quot;name&quot;&#x2F;&gt;</span><br><span class="line">        &lt;result property&#x3D;&quot;age&quot; column&#x3D;&quot;age&quot;&#x2F;&gt;</span><br><span class="line">        &lt;association property&#x3D;&quot;idCard&quot; column&#x3D;&quot;idCard_id&quot; javaType&#x3D;&quot;gzc.pojo.IdCard&quot; select&#x3D;&quot;gzc.dao.IdCardDao.selectCodeById&quot;&#x2F;&gt;</span><br><span class="line">    &lt;&#x2F;resultMap&gt;</span><br><span class="line">    &lt;select id&#x3D;&quot;selectUserById_1&quot; parameterType&#x3D;&quot;Integer&quot; resultMap&#x3D;&quot;userAndIdCard_1&quot;&gt;</span><br><span class="line">        select * from user where id&#x3D;#&#123;id&#125;</span><br><span class="line">    &lt;&#x2F;select&gt;</span><br><span class="line">    &lt;!--一对一级联查询方法二：连接查询，嵌套结果，执行一个SQL语句--&gt;</span><br><span class="line">    &lt;resultMap id&#x3D;&quot;userAndIdCard_2&quot; type&#x3D;&quot;gzc.pojo.User&quot;&gt;</span><br><span class="line">        &lt;id property&#x3D;&quot;id&quot; column&#x3D;&quot;id&quot;&#x2F;&gt;</span><br><span class="line">        &lt;result property&#x3D;&quot;name&quot; column&#x3D;&quot;name&quot;&#x2F;&gt;</span><br><span class="line">        &lt;result property&#x3D;&quot;age&quot; column&#x3D;&quot;age&quot;&#x2F;&gt;</span><br><span class="line">        &lt;association property&#x3D;&quot;idCard&quot; javaType&#x3D;&quot;gzc.pojo.IdCard&quot;&gt;</span><br><span class="line">            &lt;id property&#x3D;&quot;id&quot; column&#x3D;&quot;idcard_id&quot;&#x2F;&gt;</span><br><span class="line">            &lt;result property&#x3D;&quot;code&quot; column&#x3D;&quot;code&quot;&#x2F;&gt;</span><br><span class="line">        &lt;&#x2F;association&gt;</span><br><span class="line">    &lt;&#x2F;resultMap&gt;</span><br><span class="line">    &lt;select id&#x3D;&quot;selectUserById_2&quot; parameterType&#x3D;&quot;Integer&quot; resultMap&#x3D;&quot;userAndIdCard_2&quot;&gt;</span><br><span class="line">        select u.*,ic.code from user u, idcard ic where u.idcard_id&#x3D;ic.id and u.id&#x3D;#&#123;id&#125;</span><br><span class="line">    &lt;&#x2F;select&gt;</span><br><span class="line">    &lt;!--一对一级联查询方法三：连接查询，执行一个SQL语句，结果通过POJO类存储--&gt;</span><br><span class="line">    &lt;select id&#x3D;&quot;selectUserById_3&quot; parameterType&#x3D;&quot;Integer&quot; resultType&#x3D;&quot;gzc.pojo.UserDetail&quot;&gt;</span><br><span class="line">        select u.* ,ic.code from user u, idcard ic where u.idcard_id&#x3D;ic.id and u.id&#x3D;#&#123;id&#125;</span><br><span class="line">    &lt;&#x2F;select&gt;POJO</span><br><span class="line">&lt;&#x2F;mapper&gt;</span><br></pre></td></tr></table></figure>
<p><strong>对于方法三，返回结果用POJO类接收，所以创建一个POJO类：UserDetail.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserDetail</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> Integer id;</span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="keyword">private</span> Integer age;</span><br><span class="line">    <span class="keyword">private</span> String code;</span><br><span class="line">	<span class="comment">//省略了getter和setter方法</span></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">toString</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">"UserDetail&#123;"</span> +</span><br><span class="line">                <span class="string">"id="</span> + id +</span><br><span class="line">                <span class="string">", name='"</span> + name + <span class="string">'\''</span> +</span><br><span class="line">                <span class="string">", age="</span> + age +</span><br><span class="line">                <span class="string">", code='"</span> + code + <span class="string">'\''</span> +</span><br><span class="line">                <span class="string">'&#125;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>编写mybatisp核心配置文件mybatis-config.xml ：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version&#x3D;&quot;1.0&quot; encoding&#x3D;&quot;UTF-8&quot;?&gt;</span><br><span class="line">&lt;!DOCTYPE configuration</span><br><span class="line"> PUBLIC &quot;-&#x2F;&#x2F;mybatis.org&#x2F;&#x2F;DTD Config 3.0&#x2F;&#x2F;EN&quot;</span><br><span class="line"> &quot;http:&#x2F;&#x2F;mybatis.org&#x2F;dtd&#x2F;mybatis-3-config.dtd&quot;&gt;</span><br><span class="line">&lt;configuration&gt;</span><br><span class="line">	&lt;!--利用Mybatis的延迟加载可以一定程度上提高查询效率--&gt;</span><br><span class="line">	&lt;settings&gt;</span><br><span class="line">		&lt;!--打开延迟加载的开关--&gt;</span><br><span class="line">		&lt;setting name&#x3D;&quot;lazyLoadingEnabled&quot; value&#x3D;&quot;true&quot;&#x2F;&gt;</span><br><span class="line">		&lt;!--将积极加载改为按需加载--&gt;</span><br><span class="line">		&lt;setting name&#x3D;&quot;aggressiveLazyLoading&quot; value&#x3D;&quot;false&quot;&#x2F;&gt;</span><br><span class="line">	&lt;&#x2F;settings&gt;</span><br><span class="line">	&lt;!--告诉mybatis映射文件的位置--&gt;</span><br><span class="line">	&lt;mappers&gt;</span><br><span class="line">		&lt;mapper resource&#x3D;&quot;gzc&#x2F;mapper&#x2F;UserMapper.xml&quot; &#x2F;&gt;</span><br><span class="line">		&lt;mapper resource&#x3D;&quot;gzc&#x2F;mapper&#x2F;IdCardMapper.xml&quot; &#x2F;&gt;</span><br><span class="line">	&lt;&#x2F;mappers&gt;</span><br><span class="line">&lt;&#x2F;configuration&gt;</span><br></pre></td></tr></table></figure>
<p><strong>UserController</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Controller</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserController</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">     <span class="keyword">private</span> UserDao userDao;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">test</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="comment">//查询一个用户信息</span></span><br><span class="line">        User user1 =userDao.selectUserById_1(<span class="number">1</span>);</span><br><span class="line">        System.out.println(user1);</span><br><span class="line">        System.out.println(<span class="string">"------------------------------------"</span>);</span><br><span class="line">        User user2 =userDao.selectUserById_2(<span class="number">1</span>);</span><br><span class="line">        System.out.println(user2);</span><br><span class="line">        System.out.println(<span class="string">"------------------------------------"</span>);</span><br><span class="line">        UserDetail user3 =userDao.selectUserById_3(<span class="number">1</span>);</span><br><span class="line">        System.out.println(user3);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>测试结果：<img src="https://img-blog.csdnimg.cn/20200229203319903.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMTkzMTMz,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<h3 id="一对多级联查询"><a href="#一对多级联查询" class="headerlink" title="一对多级联查询"></a>一对多级联查询</h3><p>一对多级联关系，例如一个用户可以有多个订单，但是一个订单只属于一个用户。在Mybatis中，通过通过&lt; resultMap&gt;元素的子元素&lt; collection&gt;处理一对多级联关系。&lt; collection&gt;中有一个<code>ofType</code>属性，表示集合中的元素类型。</p>
<p>在数据中，创建一个订单表<code>orders</code>，该表中的外键为前面创建的<code>User</code>表的主键。<br><strong>创建订单持久化类</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Orders</span> </span>&#123;</span><br><span class="line">    <span class="comment">//对应数据表的字段</span></span><br><span class="line">    <span class="keyword">private</span> Integer id;</span><br><span class="line">    <span class="keyword">private</span> String ordersn;</span><br><span class="line">	<span class="comment">//省略setter和getter方法</span></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">toString</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">"Orders&#123;"</span> +</span><br><span class="line">                <span class="string">"id="</span> + id +</span><br><span class="line">                <span class="string">", ordersn='"</span> + ordersn + <span class="string">'\''</span> +</span><br><span class="line">                <span class="string">'&#125;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>在前面创建的User类中添加下面属性：</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//一对多级联查询，用户关联的订单</span></span><br><span class="line"><span class="keyword">private</span> List&lt;Orders&gt; orders;</span><br><span class="line"><span class="comment">//并且添加setter和getter方法</span></span><br></pre></td></tr></table></figure>
<p><strong>编写SQL映射文件：</strong><br>OrdersMapper.xml</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;mapper namespace&#x3D;&quot;gzc.dao.OrdersDao&quot; &gt;</span><br><span class="line">    &lt;select id&#x3D;&quot;selectOrdersByUserId&quot; resultType&#x3D;&quot;gzc.pojo.Orders&quot; parameterType&#x3D;&quot;Integer&quot;&gt;</span><br><span class="line">        select * from orders where user_id&#x3D;#&#123;id&#125;</span><br><span class="line">    &lt;&#x2F;select&gt;</span><br><span class="line">&lt;&#x2F;mapper&gt;</span><br></pre></td></tr></table></figure>
<p>在UserMapper.xml的方法一的基础上，向&lt; resultMap&gt;元素添加<code>&lt; collection&gt;</code>，如下所示：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&lt;!--根据id查个人信息--&gt;</span><br><span class="line">   &lt;!-- 一对一级联查询方法一：嵌套查询，执行两个SQL语句 --&gt;</span><br><span class="line">   &lt;resultMap type&#x3D;&quot;gzc.pojo.User&quot; id&#x3D;&quot;userAndIdCard_1&quot;&gt;</span><br><span class="line">       &lt;id property&#x3D;&quot;id&quot; column&#x3D;&quot;id&quot;&#x2F;&gt;</span><br><span class="line">       &lt;result property&#x3D;&quot;name&quot; column&#x3D;&quot;name&quot;&#x2F;&gt;</span><br><span class="line">       &lt;result property&#x3D;&quot;age&quot; column&#x3D;&quot;age&quot;&#x2F;&gt;</span><br><span class="line">        &lt;association property&#x3D;&quot;idCard&quot; column&#x3D;&quot;idCard_id&quot; javaType&#x3D;&quot;gzc.pojo.IdCard&quot; select&#x3D;&quot;gzc.dao.IdCardDao.selectCodeById&quot;&#x2F;&gt;</span><br><span class="line">       &lt;!--一对多级联查询，ofType表示集合的类型，传入用户id查询订单--&gt;</span><br><span class="line">       &lt;collection property&#x3D;&quot;orders&quot; ofType&#x3D;&quot;gzc.pojo.Orders&quot; column&#x3D;&quot;id&quot;  select&#x3D;&quot;gzc.dao.OrdersDao.selectOrdersByUserId&quot;&#x2F;&gt;</span><br><span class="line">   &lt;&#x2F;resultMap&gt;</span><br><span class="line">   &lt;select id&#x3D;&quot;selectUserById_1&quot; parameterType&#x3D;&quot;Integer&quot; resultMap&#x3D;&quot;userAndIdCard_1&quot;&gt;</span><br><span class="line">       select * from user where id&#x3D;#&#123;id&#125;</span><br><span class="line">   &lt;&#x2F;select&gt;</span><br></pre></td></tr></table></figure>
<p>举一反三，方法二和方法三就不举例了。<br><strong>编写OrdersDao接口：</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Repository</span></span><br><span class="line"><span class="meta">@Mapper</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">OrdersDao</span> </span>&#123;</span><br><span class="line">    <span class="function">List&lt;Orders&gt; <span class="title">selectOrdersByUserId</span><span class="params">(Integer uid)</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>注意：配置Mapper位置<code>&lt;mapper resource=&quot;gzc/mapper/OrdersMapper.xml&quot; /&gt;</code><br><strong>测试：</strong><br><img src="https://img-blog.csdnimg.cn/20200301002550671.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMTkzMTMz,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<h3 id="多对多级联查询"><a href="#多对多级联查询" class="headerlink" title="多对多级联查询"></a>多对多级联查询</h3><p>Mybatis没有实现多对多级联查询，这是因为多对多级联查询可以通过两个一对多级联进行查询。例如，一个订单可以有很多种商品，一种商品可以对应多个订单。</p>
<p>在mybatis创建商品<code>product</code>表和<code>orders_detial</code>表。其中<code>orders_detial</code>表存储订单和商品的多对多级联关系。<br><strong>创建持久化类Product</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Product</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> Integer id;</span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">double</span> price;</span><br><span class="line">    <span class="comment">//多对多中的一对多</span></span><br><span class="line">    <span class="keyword">private</span> List&lt;Orders&gt; ordersList;</span><br><span class="line">	<span class="comment">//省略setter和getter方法，以及toString方法</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>在Orders类中添加属性：</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//多对多中的一对多</span></span><br><span class="line">	<span class="keyword">private</span> List&lt;Product&gt; productList;</span><br></pre></td></tr></table></figure>

<p><strong>在OrdersMapper.xml 添加：</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">&lt;!--查询所有订单以及其所有商品--&gt;</span><br><span class="line">   &lt;resultMap id&#x3D;&quot;ordersAndProduct&quot; type&#x3D;&quot;gzc.po.Orders&quot;&gt;</span><br><span class="line">       &lt;id property&#x3D;&quot;id&quot; column&#x3D;&quot;id&quot;&#x2F;&gt;</span><br><span class="line">       &lt;result property&#x3D;&quot;ordersn&quot; column&#x3D;&quot;ordersn&quot;&#x2F;&gt;</span><br><span class="line">       &lt;collection property&#x3D;&quot;productList&quot; ofType&#x3D;&quot;gzc.po.Product&quot;&gt;</span><br><span class="line">           &lt;id property&#x3D;&quot;id&quot; column&#x3D;&quot;pid&quot;&#x2F;&gt;</span><br><span class="line">           &lt;result property&#x3D;&quot;name&quot; column&#x3D;&quot;name&quot;&#x2F;&gt;</span><br><span class="line">           &lt;result property&#x3D;&quot;price&quot; column&#x3D;&quot;price&quot;&#x2F;&gt;</span><br><span class="line">       &lt;&#x2F;collection&gt;</span><br><span class="line">   &lt;&#x2F;resultMap&gt;</span><br><span class="line">   &lt;select id&#x3D;&quot;selectAllOrdersAndProduct&quot; resultMap&#x3D;&quot;ordersAndProduct&quot;&gt;</span><br><span class="line">       select o.*,p.id as pid,p.name,p.price from orders o,product p,orders_detail od</span><br><span class="line">       where od.order_id&#x3D;o.id and od.product_id&#x3D;p.id</span><br><span class="line">   &lt;&#x2F;select&gt;</span><br></pre></td></tr></table></figure>
<p><strong>在OrdersDao接口中添加相应的方法 ：</strong><code>List&lt;Orders&gt; selectAllOrdersAndProduct();</code></p>
<p>MoreToMoreController</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Controller</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MoreToMoreController</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> OrdersDao ordersDao;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">test</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        List&lt;Orders&gt; ordersList = ordersDao.selectAllOrdersAndProduct();</span><br><span class="line">        <span class="keyword">for</span> (Orders order : ordersList) &#123;</span><br><span class="line">            System.out.println(order);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>测试结果 ：<br><img src="https://img-blog.csdnimg.cn/20200301154020832.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMTkzMTMz,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>

    </div>

    
    
    
        <div class="reward-container">
  <div></div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/blog/uploads/wechatpay.jpg" alt="小郭 微信支付">
        <p>微信支付</p>
      </div>

  </div>
</div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/blog/tags/Java/" rel="tag"><i class="fa fa-tag"></i> Java</a>
              <a href="/blog/tags/Mybatis/" rel="tag"><i class="fa fa-tag"></i> Mybatis</a>
              <a href="/blog/tags/SQL/" rel="tag"><i class="fa fa-tag"></i> SQL</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/2020/02/28/Mybatis%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86%E5%8F%8A%E5%85%A5%E9%97%A8demo/" rel="prev" title="Mybatis工作原理及入门demo">
      <i class="fa fa-chevron-left"></i> Mybatis工作原理及入门demo
    </a></div>
      <div class="post-nav-item">
    <a href="/blog/2020/03/03/Spring%20MVC%E5%85%A5%E9%97%A8/" rel="next" title="Spring MVC入门">
      Spring MVC入门 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#一对一级联查询"><span class="nav-text">一对一级联查询</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#一对多级联查询"><span class="nav-text">一对多级联查询</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#多对多级联查询"><span class="nav-text">多对多级联查询</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="小郭"
      src="/blog/uploads/avatar.jpg">
  <p class="site-author-name" itemprop="name">小郭</p>
  <div class="site-description" itemprop="description">一个还在不断学习的编程小白！</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">26</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/blog/categories/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/blog/tags/">
          
        <span class="site-state-item-count">44</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/GZC986707252" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;GZC986707252" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/u/3278894871" title="微博 → https:&#x2F;&#x2F;weibo.com&#x2F;u&#x2F;3278894871" rel="noopener" target="_blank"><i class="fa fa-fw fa-weibo"></i>微博</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://blog.csdn.net/qq_41193133" title="CSDN → https:&#x2F;&#x2F;blog.csdn.net&#x2F;qq_41193133" rel="noopener" target="_blank"><i class="fa fa-fw fa-globe"></i>CSDN</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:986707252@qq.com" title="E-Mail → mailto:986707252@qq.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">小郭</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v4.2.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> v7.7.2
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>


  <script defer src="/blog/lib/three/three.min.js"></script>
    <script defer src="/blog/lib/three/canvas_lines.min.js"></script>


  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>




  
<script src="/blog/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = '昵称,邮箱,链接';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : true,
      appId      : 'dQIv9pCVNauk7ezmEU35I8sW-gzGzoHsz',
      appKey     : '2BGfzddNSeijXJJtTofkbuJx',
      placeholder: "走过路过，千万不要错过，一起聊聊吧！",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : '' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>